package lab_2_server.handlers;



import ProtocolXML.* ;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import lab_2_server.MyLogger;
import lab_2_server.Server;

/**
 *  Class is root for classes of "ServerHandler" and "UserHandler"
 * @author pacific
 */
public abstract class AbstractHandler {

    /** Get NickName dependence of UserID (Dependenc need for servers) */
    public abstract String getNickname( int idOfUser ) ;

    /** Write message to handled entity (Client, server, etc)*/
    public void writeMessage(Message msg) {
        try {
            msg.write(getOStream()) ;
        } catch (IOException ex) {
            MyLogger.putMessange("Exception write message. "+ex);
        }
    }


    //-----Fields-----

    private Socket socket;
    private Server server;

    private InputStream iStream ;
    private OutputStream oStream ;


    //-----GETTERS AND SETTERS-----

    //For "Socket"
    protected final Socket getSocket() {
        return socket;
    }
    public final void setSocket(Socket socket) {
        this.socket = socket;
    }
    //For "Server"
    protected final Server getServer() {
        return server;
    }
    protected final void setServer(Server server) {
        this.server = server;
    }
    //For "InputStream"
    protected final InputStream getIStream() {
        return iStream;
    }
    protected final void setIStream(InputStream iStream) {
        this.iStream = iStream;
    }
    //For "OutputStream"
    protected final OutputStream getOStream() {
        return oStream;
    }
    protected final void setOStream(OutputStream oStream) {
        this.oStream = oStream;
    }
}
